﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace _2DGame
{
    class GameBordI
    {
        Texture2D _ClockTexture;
        Vector2 _ClockPosition;
        static SpriteFont _ClockTextTexture;
        Vector2 _ClockTextPosition;
        Texture2D _LifeTexture;
        Texture2D _LostLifeTexture;
        static int _Time = 0;//save sec
        static ulong _Points = 0;
        static int _counter = 0;//a counter for if points shall add
        int _TimeCounter = 0;//a counter for if time shall add
        static int _Min = 0;//Save min
        /// <summary>
        /// construktor for storing textures
        /// </summary>
        /// <param name="clockTexture"></param>
        /// <param name="clockTextTexture"></param>
        /// <param name="LifeTexture"></param>
        /// <param name="LostLifeTexture"></param>
        /// <param name="clockPosition"></param>
        /// <param name="clockTextPosition"></param>
        public GameBordI(Texture2D[] Intexture, SpriteFont clockTextTexture,Vector2[] Inposition)
        {
            _ClockTexture = Intexture[0];//saving in texture
            _ClockPosition = Inposition[0];
            _ClockTextTexture = clockTextTexture;
            _ClockTextPosition = Inposition[1];
            _LifeTexture = Intexture[1];
            _LostLifeTexture = Intexture[2];


        }
        /// <summary>
        /// Drawing tha standra interface
        /// </summary>
        /// <param name="spriteBatch"></param>
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();
            //Drawing the clock.
            spriteBatch.Draw(_ClockTexture, _ClockPosition, Color.White);
            spriteBatch.End();
        }
        /// <summary>
        /// Update the time and show it on the screen.
        /// </summary>
        /// <param name="spriteBatch"></param>
        /// <param name="inTime">The time that is going to be shown.</param>
        public void UpdateTime(SpriteBatch spriteBatch)
        {
            _TimeCounter++;// increase the counter
            if (_TimeCounter > 100)
            {
                _Time++;// increase the time
                _TimeCounter = 0;//reset the counter
                if (_Time == 60)
                {
                    _Time = 0;//resten the sec
                    _Min++;//increase min
                }
                if (_Time == 15 || _Time == 30 || _Time == 45 || _Time == 59)// increase the the speed 4 time in 1 min
                {
                    LevelController.IncreaseSpeed(0.5F);

                }
            }

            spriteBatch.Begin();
            if (_Time < 10)//if time is one diget draw this way
            {   //Drawing updated clock time.
                spriteBatch.DrawString(_ClockTextTexture, "0" + _Min.ToString() + ":0" + _Time.ToString(), _ClockTextPosition, Color.Black);
            }
            if (_Time >= 10)//if time is two diget draw this way
            {   //Drawing updated clock time.
                spriteBatch.DrawString(_ClockTextTexture, "0" + _Min.ToString() + ":" + _Time.ToString(), _ClockTextPosition, Color.Black);
            }
            spriteBatch.End();
        }

        /// <summary>
        /// Updating how many lifes the player got, and show it on the screen.
        /// </summary>
        /// <param name="spriteBatch"></param>
        /// <param name="LifeCount">Number of lifes left.</param>
        public void UpdateLife(SpriteBatch spriteBatch, int LifeCount)
        {
            spriteBatch.Begin();

            //If the player got 3 lifes left
            if (LifeCount == 3)
            {
                //Drawing 3 Life symbols.
                spriteBatch.Draw(_LifeTexture, new Vector2(10, 10), Color.White);
                spriteBatch.Draw(_LifeTexture, new Vector2(32, 10), Color.White);
                spriteBatch.Draw(_LifeTexture, new Vector2(54, 10), Color.White);
            }
            //If the player got 2 lifes left.
            else if (LifeCount == 2)
            {
                //Drawing 2 life symbols and 1 lost life symbol.
                spriteBatch.Draw(_LifeTexture, new Vector2(10, 10), Color.White);
                spriteBatch.Draw(_LifeTexture, new Vector2(32, 10), Color.White);
                spriteBatch.Draw(_LostLifeTexture, new Vector2(54, 10), Color.White);
            }
            //If the player got 1 life left.
            else if (LifeCount == 1)
            {
                //Drawing 1 life symbol and 2 lost life symbols.
                spriteBatch.Draw(_LifeTexture, new Vector2(10, 10), Color.White);
                spriteBatch.Draw(_LostLifeTexture, new Vector2(32, 10), Color.White);
                spriteBatch.Draw(_LostLifeTexture, new Vector2(54, 10), Color.White);
            }
            //If the player got 0 lifes left.
            else if (LifeCount == 0)
            {
                //Drawing 3 lost life symbols.
                spriteBatch.Draw(_LostLifeTexture, new Vector2(10, 10), Color.White);
                spriteBatch.Draw(_LostLifeTexture, new Vector2(32, 10), Color.White);
                spriteBatch.Draw(_LostLifeTexture, new Vector2(54, 10), Color.White);
            }

            spriteBatch.End();
        }

        /// <summary>
        /// Update the amount of points the player got, and and draw it on the screen.
        /// </summary>
        /// <param name="spriteBatch"></param>
        /// <param name="PointIncrease">The amount of points to add to the current points.</param>
        public static void UpdatePoints(SpriteBatch spriteBatch, int PointIncrease)
        {
            checked
            {
                _Points += Convert.ToUInt64(PointIncrease);
            }
            DrawTime(spriteBatch);
        }
        /// <summary>
        /// Update points over time, it update after 10 time i calld
        /// </summary>
        /// <param name="spriteBatch"></param>
        public static void UpdatePointsOverTime(SpriteBatch spriteBatch)
        {
            if (_counter > 10)//check if this method is calld more the 10 time
            {
                checked
                {
                    _Points += Convert.ToUInt64(LevelController.SpeedRunner());//add the pionts to pionts var
                }


                _counter = 0;//set so the method i not calld
            }
            DrawTime(spriteBatch);
            _counter++;
        }
        /// <summary>
        /// Draw the Time in teh scrren
        /// </summary>
        /// <param name="inspriteBatch"></param>
        private static void DrawTime(SpriteBatch inspriteBatch)
        {
            inspriteBatch.Begin();
            //Drawing the amount of points the player got on the screen.
            inspriteBatch.DrawString(_ClockTextTexture, _Points.ToString(), new Vector2(700, 10), Color.Black);
            inspriteBatch.End();
 
        }
        public static void RestGameBord()
        {
            _Time = 0;
            _Min = 0;
            _Points = 0;
        }


    }
}
